package com.ruoyi.web.controller.yf;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfInterface;
import com.ruoyi.yf.service.IYfInterfaceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医废接口Controller
 * 
 * @author
 * @date 2020-07-13
 * ffc40bac-3db5-4715-bc3a-802c5f99dcf1
 */
@Controller
@RequestMapping("/yf/interface")
public class YfInterfaceController extends BaseController
{
    private String prefix = "yf/interface";

    @Autowired
    private IYfInterfaceService yfInterfaceService;

    @RequiresPermissions("yf:interface:view")
    @GetMapping()
    public String yfInterface()
    {
        return prefix + "/interface";
    }

    /**
     * 查询医废接口列表
     * 01e057aa-51d8-494b-80fb-3bcebd9b61ef
     */
    @RequiresPermissions("yf:interface:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfInterface yfInterface)
    {
        startPage();
        List<YfInterface> list = yfInterfaceService.selectYfInterfaceList(yfInterface);
        return getDataTable(list);
    }

    /**
     * 导出医废接口列表
     * 882dcb7c-7b09-43e9-b54b-04e891b11a23
     */
    @RequiresPermissions("yf:interface:export")
    @Log(title = "医废接口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfInterface yfInterface)
    {
        List<YfInterface> list = yfInterfaceService.selectYfInterfaceList(yfInterface);
        ExcelUtil<YfInterface> util = new ExcelUtil<YfInterface>(YfInterface.class);
        return util.exportExcel(list, "interface");
    }

    /**
     * 新增医废接口
     * 2e452e44-1264-4820-be4f-9391314d72ee
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医废接口
     * d8450d03-c56a-40b0-a338-0b62fc1d863c
     */
    @RequiresPermissions("yf:interface:add")
    @Log(title = "医废接口", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfInterface yfInterface)
    {
        yfInterface.setCreateId(ShiroUtils.getUserId());
        yfInterface.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(yfInterfaceService.insertYfInterface(yfInterface));
    }

    /**
     * 修改医废接口
     * 1da81b3c-eaca-4b74-b81e-158721acf395
     */
    @GetMapping("/edit/{interfaceId}")
    public String edit(@PathVariable("interfaceId") Long interfaceId, ModelMap mmap)
    {
        YfInterface yfInterface = yfInterfaceService.selectYfInterfaceById(interfaceId);
        mmap.put("yfInterface", yfInterface);
        return prefix + "/edit";
    }

    /**
     * 修改保存医废接口
     * 99416800-8b88-4a64-8d8e-1e61c32925ff
     */
    @RequiresPermissions("yf:interface:edit")
    @Log(title = "医废接口", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfInterface yfInterface)
    {
        yfInterface.setUpdateId(ShiroUtils.getUserId());
        yfInterface.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(yfInterfaceService.updateYfInterface(yfInterface));
    }

    /**
     * 删除医废接口
     * 000c745f-716f-43aa-9a1c-6addb5ed48d7
     */
    @RequiresPermissions("yf:interface:remove")
    @Log(title = "医废接口", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yfInterfaceService.deleteYfInterfaceByIds(ids));
    }
}
